<style type="text/css">
.grid-view .status-column { width: 5%; }
.grid-view .filter-datepicker input { width: 100px; }
</style>

<?php
$this->breadcrumbs = array(
    'Articles' => array('index'),
    'Manage',
);

$this->menu = array(
    array('label' => 'Create Article', 'url' => array('create')),
);
?>

<h1>Manage Articles</h1>

<div>
    <span>Select a language : </span>
    <?php echo CHtml::dropDownList('locale',$selectedLocale,$langs); ?>
</div>

<?php
$grid = $this->widget('zii.widgets.grid.CGridView', array(
    'id' => 'article-grid',
    'dataProvider' => $model->search($selectedLocale),
    'filter' => $model,
    'selectableRows' => 2,
    'selectionChanged' => "updateSelectors",
    'columns' => array(
        array(
            'class' => 'CCheckBoxColumn',
            'value' => '$data->id',
            'htmlOptions' => array(
                'style' => 'text-align: center',
                'width' => '3%'
            ),
        ),
        array(
            'name' => 'title',
            'type' => 'raw',
            'value' => 'CHtml::link($data->localeArticle->title,url("/Article/admin/article/update",array("id"=>$data->id)))',
            'htmlOptions' => array('width' => '10%'),
        ),

        array(
            'header' => 'Image',
            'type' => 'raw',
            'value' => '(!empty($data->image)) ? CHtml::link(CHtml::image(substr($data->image,1),"",array("width"=>"50")),url("/Article/admin/article/update",array("id"=>$data->id))) : ""',
            'filter' => false,
            'htmlOptions' => array(
                'style' => 'text-align: center',
                'width' => '5%',
            ),
        ),
        array(
            'name' => 'category_id',
            'sortable' => false,
            'type' => 'raw',
            'class'=>'Site.components.CategoryDropDownListColumn',
            'rootId'=>ArticleSettings::ROOT_CATEGORY_ID,
            'locale'=>$selectedLocale,
            'value' => '$data->getLanguageCategorySection("'.$selectedLocale.'")',
            'htmlOptions' => array('width' => '5%'),
        ),
        array(
            'name' => 'on_homepage',
            'type' => 'raw',
            'value' => '($data->on_homepage==1) ? "Yes" : "No"',
            'filter' => array('0'=>'No','1'=>'Yes'),
            'htmlOptions' => array(
                'width' => '3%',
                'style' => 'text-align: center',
            ),
        ),
        array(
            'name' => 'status',
            'type' => 'raw',
            'value' => 'CHtml::link($data->statusText,"#",array("id"=>$data->id,"class"=>($data->status==1 ? "active" : "")))',
            'filter' => $model->getStatusOptions(),
            'htmlOptions' => array(
                'class' => 'status-column',
                'width' => '10%',
            ),
        ),
        array(
            'header' => 'Date created (dd/mm/yyyy)',
            'name' => 'dateCreated',
            'class'=>'Core.components.CDatePickerColumn',
            'value' => 'date("d/m/Y",strtotime($data->create_time))',
            'fromOptions' => array(
                'maxDate' => ''
            ),
            'toOptions' => array(
                'maxDate' => ''
            ),
            'htmlOptions'=>array(
                'width'=>'8%',
                'style' => 'text-align: center',
            ),
        ),
        array(
            'class' => 'CButtonColumn',
            'template' => '{update} {delete}',
            'htmlOptions' => array(
                'width' => '3%',
                'style' => 'text-align: center',
            ),
        ),
    ),
));

if ($grid->dataProvider->ItemCount) {
    $this->menu[] = array('label' => 'Delete selected items', 'url' => $this->createUrl('delete'), 'linkOptions' => array('onclick' => 'return multipleDelete("article-grid",this.href)'));
}
Yii::app()->clientScript->registerScriptFile(Yii::app()->core->AssetUrl . '/scripts/gridview.js', CClientScript::POS_BEGIN);
?>


<?php
$script = '
	$(".grid-view .status-column a").live("click", function(){
		status = $(this).attr("class")==""?"inactive": $(this).attr("class");
		$.ajax({
			url:"' . serviceUrl('Article.ArticleAPI.setStatus', 'ajax') . '",
			type: "get",
			data: {"status": status, "id": $(this).attr("id")},
			success: function(){
				$.fn.yiiGridView.update("article-grid");
			}
		});
		return false;
	})
';
cs()->registerScript('set-status', $script, CClientScript::POS_READY);
?>

<script type="text/javascript">
$('#locale').change(function(){
    window.location.href = '<?php echo $this->createUrl('/Article/admin/Article/admin'); ?>&locale='+$(this).val();        
});
</script>